<?php

namespace app\web\controller;
use app\web\model\StoreGoodsTypeModel;
use app\common\controller\StoreBaseController;
use think\Db;
/**
 * 商家自定义商品分类
 */
class StoreGoodsTypeController extends StoreBaseController
{
 	 protected $model;
	
    protected function _initialize() {
        parent::_initialize();
        $this->model = new StoreGoodsTypeModel();
		//获取商家自定义商品分类
		$list = $this->model->where('agent_id',session('storeInfo')['id'])->select();
		$this->assign('list',$list);
    }
    /**
     * 商家自定义商品分类
     * @author [lx] 
     */
    public function index( $page = 1){
        return $this->fetch();
    }


    /**
     * 
     * 添加
     * @author [lx] 
     */
    public function add($pid = '')
    {
        if(request()->isAjax()){
        	$param=input('post.');
			$param['add_time']=now_time();
			//分类所属店铺id
			$param['agent_id']=session('storeInfo')['id'];
			
			if ($this->model->allowField(true)->save($param) !== false) {
                    $this->success('添加成功', url('store_goods_type/index'));
            } else {
                $this->error('添加失败');
            }
        }
		$list=$this->model->select();
		$this->assign('pid',$pid);
        return $this->fetch();
    }


    /**
     * [edit 商家自定义编辑]
     * @return [type] [description]
     * @author [lx]
     */
    public function edit($id)
    {
        if(request()->isAjax()){
            $param = input('post.');         
         	if ($this->model->allowField(true)->save($param,$id) !== false) {
                    $this->success('修改成功', url('store_goods_type/index'));
            } else {
                $this->error('修改失败');
            }
        }
        $id = input('param.id');
        $this->assign('model',$this->model->find($id));
        return $this->fetch();
    }



    /**
     * [del删除]
     * @author [lx] 
     */
    public function delete()
    {
        $id = input('param.id');
        if ($this->model->destroy($id)) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }
}